from tkinter import Tk
from tkinter.messagebox import askyesno
def closeWindow():
    ans = askyesno(title='Warning', message='Close the window?')
    if ans:
        root.destroy()

    else:
        return

if __name__ == '__main__':
    root = Tk()
    root.protocol('WM_DELETE_WINDOW', closeWindow)
    root.mainloop()